const allDom = document.querySelectorAll(".line");
function isOdd(number) {
  // true 为奇数 false 为偶数
  return number % 2 !== 0;
}
function addMouseOverEvent(childrenNodes, item, index) {
  item.addEventListener("mouseover", (event) => {
    const inde = Array.from(childrenNodes).indexOf(event.target);
    if (inde === -1) return;
    // 左
    inde !== 0 &&
      childrenNodes[inde - 1] &&
      (childrenNodes[inde - 1].style.transform = "scale(0.8)");
    // 右
    childrenNodes[inde + 1] &&
      (childrenNodes[inde + 1].style.transform = "scale(0.8)");
    // 上
    if (index !== 0) {
      const flag = this.isOdd(index);
      const bortherNode = allDom[index - 1];
      const bortherChildrenNodes = bortherNode.children;
      if (!flag) {
        bortherChildrenNodes[inde].style.transform = "scale(0.8)";
        bortherChildrenNodes[inde + 1] &&
          (bortherChildrenNodes[inde + 1].style.transform = "scale(0.8)");
      } else {
        bortherChildrenNodes[inde - 1].style.transform = "scale(0.8)";
        bortherChildrenNodes[inde] &&
          (bortherChildrenNodes[inde].style.transform = "scale(0.8)");
      }
    }
    // 下
    if (index != allDom.length) {
      const flag = this.isOdd(index);
      const bortherNode = allDom[index + 1];
      const bortherChildrenNodes = bortherNode.children;
      if (!flag) {
        inde !== 0 &&
          bortherChildrenNodes[inde] &&
          (bortherChildrenNodes[inde].style.transform = "scale(0.8)");
        bortherChildrenNodes[inde + 1] &&
          (bortherChildrenNodes[inde + 1].style.transform = "scale(0.8)");
      } else {
        inde !== 0 &&
          bortherChildrenNodes[inde - 1] &&
          (bortherChildrenNodes[inde - 1].style.transform = "scale(0.8)");
        bortherChildrenNodes[inde] &&
          (bortherChildrenNodes[inde].style.transform = "scale(0.8)");
      }
    }
  });
}
function addMouseOutEvent(childrenNodes, item, index) {
  item.addEventListener("mouseout", (event) => {
    const inde = Array.from(childrenNodes).indexOf(event.target);
    if (inde === -1) return;
    // 左
    inde !== 0 &&
      childrenNodes[inde - 1] &&
      (childrenNodes[inde - 1].style.transform = "scale(1)");
    // 右
    childrenNodes[inde + 1] &&
      (childrenNodes[inde + 1].style.transform = "scale(1)");
    // 上
    if (index !== 0) {
      const bortherNode = allDom[index - 1];
      const bortherChildrenNodes = bortherNode.children;
      bortherChildrenNodes[inde].style.transform = "scale(1)";
      bortherChildrenNodes[inde + 1] &&
        (bortherChildrenNodes[inde + 1].style.transform = "scale(1)");
    }
    // 下
    if (index != allDom.length - 1) {
      const bortherNode = allDom[index + 1];
      const bortherChildrenNodes = bortherNode.children;
      inde !== 0 &&
        childrenNodes[inde] &&
        (childrenNodes[inde].style.transform = "scale(1)");
      childrenNodes[inde + 1] &&
        (childrenNodes[inde + 1].style.transform = "scale(1)");
    }
  });
}
if (allDom?.length > 0) {
  allDom.forEach((item, index) => {
    const childrenNodes = allDom[index].children;
    this.addMouseOverEvent(childrenNodes, item, index);
    this.addMouseOutEvent(childrenNodes, item, index);
  });
}
